#include"DoubleLinkList.h"

string LinkListToStr(DLinkList L)
{
	DLNode* cur = L->next;
	string res="";
	while (cur)
	{

		res += to_string(cur->data);
		cur = cur->next;
	}
	return res;
}



DLinkList StrToLinkList(string str)
{
	int index = str.size() - 1;
	DLinkList res = new DLNode;
	if (!res)
		exit(-1);
	res->prior=res->next = NULL;
	string Child_str="";
	while (index >= 0)
	{
		Child_str += str[index--];
		if (Child_str.size() == 3)
		{
			reverse(Child_str.begin(), Child_str.end());
			DLinkList newnode = new DLNode;
			newnode->data = stoi(Child_str);
			/*头插至res*/
			newnode->next = res->next;
			if (res->next)
				res->next->prior = newnode;
			newnode->prior = res;
			res->next = newnode;
			Child_str = "";
		}
	}
	if (Child_str.size() < 3 && Child_str.size()>0)
	{
		reverse(Child_str.begin(), Child_str.end());
		DLinkList newnode = new DLNode;
		newnode->data = stoi(Child_str);
		/*头插至res*/
		newnode->next = res->next;
		if (res->next)
			res->next->prior = newnode;
		newnode->prior = res;
		res->next = newnode;
	}
	return res;
}